﻿using System.Collections.Generic;
using System.Windows.Media;
using Dsl.Ped.Common.Commands;
using Dsl.Ped.Framework.Common;
using System.Windows.Controls;
using Dsl.Ped.Framework.Projections;

namespace Dsl.Ped.AddIn.Java.Generated
{
    /// <summary>
    /// This is the class that enhances the <see cref="Constructor"/> class 
    /// provided in the model of projections, these are organized into containers
    /// </summary>
    public partial class Constructor : IProjective
    {
        public override List<IProjectionContainer> GetProjectionContainers()
        {
            List<IProjectionContainer> projections = new List<IProjectionContainer>();
            projections.Add(new ProjectionContainer("Constructor")
                .RegisterProjection("constructor", 
                    ObjectProjectionFactory.GetBlockProjection( 
                        ObjectProjectionFactory.GetBlockProjection( 
                            ValueProjectionFactory.GetTextBoxProjection(this, () => name),
                            GetParametersProjection(),
                            bp => { bp.Foreground = new SolidColorBrush(Colors.Red); }),
                                                    bp =>
                                                    {
                                                        bp.Orientation = Orientation.Vertical;
                                                        bp.StartTag = "{";
                                                        bp.EndTag = "}";
                                                    })));
            projections.Add(new ProjectionContainer("Constructor name")
                .RegisterProjection("prameters", CollectionProjectionFactory.GetVerticalProjection(this, () => parameters))
                .RegisterProjection("customerName", ValueProjectionFactory.GetTextBoxProjection(this, () => name)));
            return projections;
        }

        private IProjection GetParametersProjection()
        {
            return CollectionProjectionFactory.GetExpandableCollectionProjection(
                this,
                () => parameters,
                exp => {
                    exp.Commands = new List<IMenuCommand>() {
                        new MenuCommand<Parameter>(
                            "Add Parameter",
                            (param) => { 
                                int position = 0;
                                if (param != null)
                                position =
                                    parameters.IndexOf((Parameter)param) + 1;
                                    this.parameters.Insert(
                                        position,
                                        new Parameter()
                                            {
                                                name = "parameter",
                                                type = "Void"
                                            });
                                })
                                        };
                    exp.RemoveItem = parameter =>
                        { parameters.Remove((Parameter)parameter); };
                });
        }
    }
}
